package com.gxk.actor;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.gxk.res.PublicConst;
import com.gxk.res.SpriteFactory;

public class FloorActor extends Actor {
	private float x;
	private float y;

	private Sprite floorSprite;
	private Rectangle floorRectangle;
	private boolean isMove;

	public FloorActor(boolean isMove) {
		this.x = 0;
		this.y = 0;
		this.isMove = isMove;

		this.create();
		this.rectangleInit();
	}

	private void create() {
		floorSprite = SpriteFactory.getFloorsprite();
	}

	private void rectangleInit() {
		this.floorRectangle = new Rectangle(this.x, this.y,
				PublicConst.WORLD_WIDTH, 116);
	}

	public void act(float delta) {
		this.update();
		super.act(delta);
	}

	private void update() {
		if (isMove) {
			if (this.x > -PublicConst.WORLD_WIDTH) {
				this.x -= PublicConst.MOVE_SPEED;
			} else {
				this.x = 0;
			}
		}
	}

	@Override
	public void draw(Batch batch, float parentAlpha) {

		batch.draw(this.floorSprite, this.x, this.y);
		batch.draw(this.floorSprite, this.x + PublicConst.WORLD_WIDTH, this.y);

		super.draw(batch, parentAlpha);
	}

	public Rectangle getFloorRectangle() {
		return floorRectangle;
	}

	public void setMoveState(boolean isMove) {
		this.isMove = isMove;
	}
}
